package org.example.curriculum_design_6_16.controller;

import org.example.curriculum_design_6_16.entity.pojo.IpScoringRule;
import org.example.curriculum_design_6_16.entity.vo.Result;
import org.example.curriculum_design_6_16.service.IpScoringRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ipScoringRule")
public class IpScoringRuleController {
    @Autowired
    private IpScoringRuleService ipScoringRuleService;

    @PostMapping
    public Result<Integer> addIpScoringRule(@RequestBody IpScoringRule rule) {
        try {
            return Result.success(ipScoringRuleService.addIpScoringRule(rule));
        } catch (Exception e) {
            return Result.error("添加知识产权评分规则失败: " + e.getMessage());
        }
    }

    @PutMapping
    public Result<Integer> updateIpScoringRule(@RequestBody IpScoringRule rule) {
        try {
            return Result.success(ipScoringRuleService.updateIpScoringRule(rule));
        } catch (Exception e) {
            return Result.error("更新知识产权评分规则失败: " + e.getMessage());
        }
    }

    @DeleteMapping("/{id}")
    public Result<Integer> deleteIpScoringRule(@PathVariable Integer id) {
        try {
            return Result.success(ipScoringRuleService.deleteIpScoringRule(id));
        } catch (Exception e) {
            return Result.error("删除知识产权评分规则失败: " + e.getMessage());
        }
    }

    @GetMapping("/{id}")
    public Result<IpScoringRule> getIpScoringRuleById(@PathVariable Integer id) {
        try {
            return Result.success(ipScoringRuleService.getIpScoringRuleById(id));
        } catch (Exception e) {
            return Result.error("获取知识产权评分规则失败: " + e.getMessage());
        }
    }

    @GetMapping
    public Result<List<IpScoringRule>> getAllIpScoringRules() {
        try {
            return Result.success(ipScoringRuleService.getAllIpScoringRules());
        } catch (Exception e) {
            return Result.error("获取所有知识产权评分规则失败: " + e.getMessage());
        }
    }
}